package ifwhilefor;

import java.util.Scanner;

//本程序的功能是判断输入的数字是否是回文数
public class PalindromeNumber1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个整数");
        int number = sc.nextInt(), num = number, count = 0, num_more, num_less, i = 1;
        //此处的num与count是用于记录整数number有几位
        while (num != 0) {
            num /= 10;
            count++;
        }
        //当number的位数(count)为1时,无需计算
        if (count == 1)
            System.out.println(number + "是回文数");
        else {
            //number有几位,则循环count/2(舍余)次
            for (i = 1; i <= count / 2; i++) {
                //初始化参与求单个位数的变量
                num_more = 1;
                num_less = 1;
                //计算求位数的值
                for (int j = 0; j < count - i; j++)
                    num_more *= 10;
                for (int j = 0; j < i - 1; j++)
                    num_less *= 10;
                //计算并对比
                if (number % (num_more * 10) / num_more != number % (num_less * 10) / num_less) {
                    System.out.println(number + "不是回文数");
                    break;
                }
            }
        }
        if (i > count / 2)
            System.out.println(number + "是回文数");
    }
}
